/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sistema.clinica.riobamba.desktop;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

/**
 *
 * @author xavier
 */
public class LoginController implements Initializable {

    @FXML
    private TextField txtCedula;
    @FXML
    private TextField txtContrasena;
    @FXML
    Label errorMessage;

    private SistemaClinicaRiobambaDesktop application;

    public void setApp(SistemaClinicaRiobambaDesktop application) {
        this.application = application;
    }

    @FXML
    private void handleLoginAction(ActionEvent event) {
        if (application == null) {
            // We are running in isolated FXML, possibly in Scene Builder.
            // NO-OP.
            errorMessage.setText("Hello " + txtCedula.getText());
        } else {
            if (!application.userLogging(txtCedula.getText(), txtContrasena.getText())) {
                errorMessage.setText(application.getMensajeError());
                if (errorMessage.getText().equals("")) {
                    errorMessage.setText("Cedula o Contraseña incorrecta");
                }
                SistemaClinicaRiobambaDesktop.setMensajeError("");
            }
        }
    }
    
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        errorMessage.setText("");
        txtCedula.setPromptText("1234567890");
    }

}
